<template>
	<view>
		<view class="head">
			<u-navbar title="消费团队" :autoBack="true" :placeholder="true" leftIconColor="#000000" :titleStyle="{color: '#000000'}" :bgColor="scrollTop > 0 ? '#ffffff' : 'transparent'">
			</u-navbar>
			<view class="flex justify-between padding-tb-xl padding-left-lg padding-right text-black3">
				<view class="flex">
					<view>
						<image :src="userInfo.userAvatarUrl ? userInfo.userAvatarUrl : '/static/my/avatar.png'" mode="widthFix" class="img-100 radius-25"></image>
					</view>
					<view class="margin-left">
						<view class="font-19 text-bold flex align-center">
							{{userInfo.nickName}}
						</view>
						<view class="margin-top-sm">
							<text class="level" style="margin-left: 0;" v-if="userInfo.userLevelName">{{userInfo.userLevelName}}</text>
						</view>
						<view class="font-13 margin-top-sm">邀请码：{{userInfo.invitationCode}} <text class="copy-btn"
								@click="copyCode(userInfo.invitationCode)">复制</text></view>
					</view>
				</view>
				<view class="flex flex-direction align-end align-center">
					<view class="font-18 text-bold">{{extend && extend.user && extend.user.orderAmount || 0}}</view>
					<view class="margin-top-sm text-gray">个人消费</view>
				</view>
			</view>
		</view>
		<view>
			<view class="text-bold font-16 text-black3 padding">
				团队消费总额：{{extend.monetary || 0}}
			</view>
			<view class="bg-white padding margin-lr margin-bottom radius-8" v-for="(item, index ) in rankList" :key="index">
				<view class="flex justify-between font-13 text-black3">
					<view class="flex">
						<view>
							<image :src="item.userAvatarUrl ? item.userAvatarUrl : '/static/my/avatar.png'" mode="widthFix" class="img-75 radius-25"></image>
						</view>
						<view class="margin-left">
							<view class="flex font-15 text-bold flex align-center">
								<view class="widthName" :class="item.deleteFlag ? 'color-g':''">{{item.nickName}}</view>
								<view class="level" v-if="item.userLevelName && !item.deleteFlag">{{item.userLevelName}}</view>
								<view class="level" v-if="item.deleteFlag">已注销</view>
							</view>
							<view class="margin-top-sm" :class="item.deleteFlag ? 'color-g':''">手机号: {{$dealTel(item.mobile) }} </view>
							<view class="margin-top-sm" :class="item.deleteFlag ? 'color-g':''">邀请人: {{$dealTel(item.refereeMobile) }}</view>
							<view class="margin-top-sm" :class="item.deleteFlag ? 'color-g':''">邀请时间: {{item.createTime}}</view>
							<view class="margin-top-sm" :class="item.deleteFlag ? 'color-g':''">客户: {{item.refereeCount || 0}}</view>
						</view>
					</view>
					<view class="text-right">
						<view class="font-18 text-theme text-bold" :class="item.deleteFlag ? 'color-g':''">{{item.orderAmount || 0}}</view>
						<view class="text-gray margin-top-xs">总额</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" color="#000000" class="padding-bottom"/>
		
	</view>
</template>

<script>
	import {
		teamRankingList
	} from '@/common/api/customer.js'
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				status: 'loading',
				pageNo: 0,
				rankList: [],
				extend: {},
				scrollTop: 0
			};
		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		onLoad() {
			this.getTeamRankingList()
		},
		onReachBottom() {
			this.getTeamRankingList()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		methods: {
			resetData() {
				this.pageNo = 0
				this.rankList = []
				this.extend = {}
			},
			getTeamRankingList() {
				this.status = 'loading'
				this.pageNo++
				teamRankingList({pageNo: this.pageNo, pageSize: 10, productArea: 2}).then(res=>{
					uni.hideLoading()
					if(res.code == 200) {
						this.rankList = this.rankList.concat(res.data)
						this.extend = res.extend || {}
						if (res.data.length < 10) {
							this.status = 'nomore'
						}
					}
				}).catch(err=>{
					uni.hideLoading()
				})
			},
			copyCode(code) {
				let that = this
				uni.setClipboardData({
					data: code,
					success: function() {
						that.$msg('复制成功')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
page {
	background: #f2f2f2;
}
</style>
<style lang="scss" scoped>
.widthName{
	width: 180rpx;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.head {
	background-image: url('/static/my/service-bg.png');
	background-size: 100% 100%;
}
.copy-btn {
	border: 2rpx solid #808080;
	color: #808080;
	font-size: 20rpx;
	padding: 2rpx 10rpx;
	margin-left: 20rpx;
	border-radius: 6rpx;
}
.level {
	background: linear-gradient(42deg, #FF0804 0%, #FC7844 100%);
	box-shadow: 0 2rpx 10rpx 1rpx rgba(250,49,33,0.24);
	color: #ffffff;
	font-size: 24rpx;
	padding: 4rpx 10rpx;
	border-radius: 8rpx;
	min-width: 96rpx;
	text-align: center;
}
</style>
